import axios from './axios'
import qs from 'qs'
import { baseUrl } from '@/config/config'
// 文件
// 大文件上传
export const bigFilePost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '',
      method: 'POST',
      headers: { 'Content-Type': 'multipart/form-data' },
      data: params,
      timeout: 600000
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 文件合并
export const mergeFilePost = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
        // 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
      },
      data: JSON.stringify(params),
      timeout: 600000
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
export const uploadFile = (params) => {
  return new Promise((resolve, reject) => {
    var formData = new FormData()
    formData.append('file', params.get('file'))  
    axios({
      url: baseUrl + '/file/handle/uploadFile?explorerId=-1&parentId=-1&name=' + params.get('name') + '&md5=' + params.get('md5'),
      method: 'POST',
      headers: { 'Content-Type': 'multipart/form-data' },
      data: formData,
      timeout: 600000
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 单个文件下载
export const downloadOneFile = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/file/handle/downloadOneFile',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      },
      data: JSON.stringify(params),
      timeout: 600000
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}

// 单个文件下载
export const getPublicUrl = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/biz/annex/getPublicUrl',
      method: 'GET',
      params
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
// 获取文件列表
export const listPublicUrl = (params) => {
  return new Promise((resolve, reject) => {
    axios({
      url: baseUrl + '/biz/annex/listPublicUrl',
      method: 'POST',
      headers: {
        'Content-Type': 'application/json; charset=utf-8'
      },
      data: JSON.stringify(params),
      timeout: 600000
    }).then(res => {
      resolve(res.data)
    }).catch(error => {
      reject(error.data)
    })
  })
}
